const {
    Mysql
} = require('../tools/utils');
module.exports = async (ctx) => {

    let {
        vid,
        type
    } = ctx.query;
    // 若为电视剧
    if (type == 1) {
        let sql = `SELECT video.*,tv.qisim FROM video RIGHT JOIN tv  ON video.vid=tv.vid WHERE video.vid=${vid}`;
        try {
            let info = (await Mysql(sql))[0];
            let listStr = Buffer.from(JSON.stringify(info)).toString('base64').replace(/A/g, '&').replace(/B/g, '%'); //第一次转base64
            ctx.state.data = {
                list: listStr,
                code: '001'
            }
        } catch (error) {
            ctx.state.data = {
                msg: 'مەغلۇپ بولدى',
                code: '002'
            }
        }
    }
    // 若为电影
    else {
        if (vid != 'undefined' && type != 'undefined') {


            try {
                let sql = `SELECT * FROM video WHERE vid=${vid}`;
                let info = (await Mysql(sql))[0];
                let listStr = Buffer.from(JSON.stringify(info)).toString('base64').replace(/A/g, '&').replace(/B/g, '%'); //第一次转base64
                ctx.state.data = {
                    list: listStr,
                    code: '001'
                }
            } catch (error) {
                ctx.state.data = {
                    msg: 'مەغلۇپ بولدى',
                    code: '002'
                }
            }
        }
    }

}